Link to this headingExecutable and Linkable Format (ELF)
Types of Files:
- Executable Files
- Shared library files
- Object files
Link to this headingLinux Kernel Image
Convert vmlinux/vmlinuz/bzImage/zImage kernel image to ELF
Multi Part Series on ELF files
Link to this headingELF Header
Read Header Information:
>>> readelf
ELF Header:
- Magic Number
- 7F 45 4C 46
- Class
- 00: Invalid
- 01: 32bit Object
- 02: 64bit Object
- Data Encoding
- 00: Invalid
- 01: Least Significant Byte First (LSB)
- 02: Most Significant Byte First (MSB)
- Version
- 01: Version of ELF 1.0
- OS ABI
- 00: None/System V (Most common)
- 01: HP-UX
- 02: NetBSD
- 03: Linux
- ABI Version
- 00: Not used
- Padding
- 00 00 00 00 00 00 00
- Type
- 00 00: No File Type
- 00 01: Relocatable file type (Object Files .o files)
- 00 02: Executable file (Non ASLR executables)
- 00 03: Shared object file (Shared Libraries and ASLR Executables)
- 00 04: Core file (Core Dumps)
- Machine Type
- 00 03: x86
- 00 08: MIPS
- 00 28: ARM
- 00 3E: amd64
- 00 B7: ARMv8
- 00 F3: RISC-V
- ELF Version
- 00 00 00 01: Always set to ELF version 1.0
- Entry point
- Entry point of the application
- Program headers offset
- The start of the Program Headers at offset from binging of the file
- Section headers offset
- The start of the Section Headers at offset from binging of the file
- Flags
- OS and Archetecture Dependent
- ELF Header Size
- Size of the Header Size (Kind of useless)
- Size of each Program Header
- All program segments are the same size
- The Number of Program Headers
- Size of each Section Header
- All sections are the same size
- The Number of Section Headers
- Section table index
- Used to resolve the names of the sections in the file
Link to this headingSegments
Also known as program headers
relevant at Runtime
Segment Header:
- Type of Segment
- 00 00: Null (Can be used to disable a segment)
- 00 01: Loaded into memory
- 00 02: Dynamic linked libraries
- 00 03: Interpreted (only ASLR has this segment)
- 00 04: Note (Hold debugger information)
- 00 05: HLIB (Not used)
- 00 06: Physical Address (Location where this will be loaded into memory)
- 00 07: Thread Local Storage (Thread Local Varbales)
- Offset
- Where in the elf file this segment starts
- Virtual Address
- Where in Virtual memory this will be located
- Physical Address
- Where in Physical memory this will be located. Only when this is the only option
- File Size
- How big the segment is
- Size of the segment in memory
- If it is larger than the file size the rest is set to 00 values
- Flags
- Permissions of the segments RWX
- Align
- Align bytes to either 4 bytes or 8 bytes
List Segments in a File:
>>> readelf
)
Link to this headingSections
Relevant at Linktime
Common Sections:
.text: code..data: initialized data..rodata: initialized read-only data..bss: uninitialized data..plt: PLT (Procedure Linkage Table) (IAT equivalent)..got: GOT entries dedicated to dynamically linked global variables..got.plt: GOT entries dedicated to dynamically linked functions..symtab: global symbol table..dynamic: Holds all needed information for dynamic linking..dynsym: symbol tables dedicated to dynamically linked symbols..strtab: string table of .symtab section..dynstr: string table of .dynsym section..interp: RTLD embedded string..rel.dyn: global variable relocation table..rel.plt: function relocation table.shstrtab: Table for the names of each of the sections
Section Header:
- Section Name
- Offset into the string table
- Type
- 00 00: Null (Ignored)
- 00 01: Process Bits
- 00 02: Symbol table (List of symbol table structures)
- 00 03: String Table (List of null terminated strings)
- 00 04: Relocation
- 00 05: Hash table
- 00 06: Dynamic linking
- 00 07: Note (Debugging info)
- 00 08: No Bits (uninitialized variables)
- 00 09: Relocation
- 00 0A: SH Library
- 00 0B: Dynmaic Symbols (List of symbol table structures)
- Flags
- 01: Writable
- 02: Allocate
- 04: Executable Instructions
- Where Address will appear in memory
- Offset of location in the elf file
- How large the Size is in the elf file
- Linked to another section
- Info
- Address Align
- Entry Size
- size for data in an array in the section
List Sections in a File:
>>> readelf
[
[
[
[
[
[
[
[
[
[
))))))
))))
))))
))